home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacPeople 2003 February 1
/
MACPEOPLE-2003-02-01.ISO.7z
/
MACPEOPLE-2003-02-01.ISO
/
ぶらりオンラインウェアの旅
/
おしゃべり漂流記
/
xGates
/
xGates 1.2 Source Code.sit
/
xGates 1.2 Source Code
/
init.c
< prev
next >
Wrap
Text File
|
2002-12-08
|
12KB
|
375 lines
/*
xGates -- Stunningly entertaining action game for MacOS Classic / MacOS X
Copyright (C) 2002 Sveinbjorn Thordarson <paladeen@soth.zoneit.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
init.c
*/
#include "structures.h"
#include "externs.h"
#include "prototypes.h"
#include "definitions.h"
#include "DrawSprocket.h"
//////////////////////////////////////////////////////
//Gone are the days of InitMenus(), QDRandseed etc.
//////////////////////////////////////////////////////
void InitToolbox (void)
{
long result;
InitCursor();
//now, let's find out what OS we're running
Gestalt(gestaltMenuMgrAttr, &result);
//if OS X
if(result & gestaltMenuMgrAquaLayoutMask)
{
gOS = kMacOSX;
}
else
{
gOS = kMacOSClassic;
}
}
//////////////////////////////////////////////////////
//Oooh, at last, my very own InitMenus function.
//////////////////////////////////////////////////////
void InitMenus (void)
{
if (gOS == kMacOSClassic)
{
//Load menus from rsrc
appleMenu = GetMenu(1000);
fileMenu = GetMenu(1001);
editMenu = GetMenu(1002);
optionsMenu = GetMenu(1003);
geekOptionsMenu = GetMenu(1004);
if (appleMenu == NULL || fileMenu == NULL || editMenu == NULL || optionsMenu == NULL || geekOptionsMenu == NULL)
{
DoAlert("¥pError loading menus.", "¥pPossible corruption of executable resource fork or out of memory.");
QuitApp();
}
//Insert them
InsertMenu(appleMenu, 0);
InsertMenu(fileMenu, 0);
InsertMenu(editMenu, 0);
InsertMenu(optionsMenu, 0);
InsertMenu(geekOptionsMenu, 0);
HideMenuBar();
}
}
//////////////////////////////////////////////////////
//Load all pic resources into offscreen pixmaps
//////////////////////////////////////////////////////
void InitGraphics (void)
{
short i;
billPtr = LoadPicToGWorld(1000);
billPix = GetGWorldPixMap(billPtr);
stevePtr = LoadPicToGWorld(1001);
stevePix = GetGWorldPixMap(stevePtr);
poofPtr = LoadPicToGWorld(1002);
poofPix = GetGWorldPixMap(poofPtr);
for (i = 0; i < 10; i++)
{
macPtr[i] = LoadPicToGWorld(2000+i);
macPix[i] = GetGWorldPixMap(macPtr[i]);
}
chainSawPtr = LoadPicToGWorld(200);
chainSawPix = GetGWorldPixMap(chainSawPtr);
chainSawBigPtr = LoadPicToGWorld(190);
chainSawBigPix = GetGWorldPixMap(chainSawBigPtr);
splashPtr = LoadPicToGWorld(100);
splashPix = GetGWorldPixMap(splashPtr);
highScorePtr = LoadPicToGWorld(110);
highScorePix = GetGWorldPixMap(highScorePtr);
buttonsPtr = LoadPicToGWorld(160);
buttonsPix = GetGWorldPixMap(buttonsPtr);
deptOfJusticePtr = LoadPicToGWorld(500);
deptOfJusticePix = GetGWorldPixMap(deptOfJusticePtr);
deptOfJusticeIconPtr = LoadPicToGWorld(501);
deptOfJusticeIconPix = GetGWorldPixMap(deptOfJusticeIconPtr);
macIconPtr = LoadPicToGWorld(300);
macIconPix = GetGWorldPixMap(macIconPtr);
billIconPtr = LoadPicToGWorld(301);
billIconPix = GetGWorldPixMap(billIconPtr);
sothPtr = LoadPicToGWorld(4000);
sothPix = GetGWorldPixMap(sothPtr);
mousePtr = LoadPicToGWorld(401);
mousePix = GetGWorldPixMap(mousePtr);
keyboardPtr = LoadPicToGWorld(400);
keyboardPix = GetGWorldPixMap(keyboardPtr);
gamePausedPtr = LoadPicToGWorld(180);
gamePausedPix = GetGWorldPixMap(gamePausedPtr);
cornerPtr[0] = LoadPicToGWorld(5000);
cornerPix[0] = GetGWorldPixMap(cornerPtr[0]);
cornerPtr[1] = LoadPicToGWorld(5001);
cornerPix[1] = GetGWorldPixMap(cornerPtr[1]);
scoreNameRectPtr = LoadPicToGWorld(195);
scoreNameRectPix = GetGWorldPixMap(scoreNameRectPtr);
haukurSplashPtr = LoadPicToGWorld(120);
haukurSplashPix = GetGWorldPixMap(haukurSplashPtr);
haukurHeadPtr = LoadPicToGWorld(130);
haukurHeadPix = GetGWorldPixMap(haukurHeadPtr);
haukurWinPtr = LoadPicToGWorld(140);
haukurWinPix = GetGWorldPixMap(haukurWinPtr);
}
//////////////////////////////////////////////////////
//Init sound channels and load SND resources
//////////////////////////////////////////////////////
void InitSound (void)
{
short i;
SndNewChannel(&weaponSndChannel, sampledSynth, initMono + initNoDrop, nil);
SndNewChannel(&billSndChannel, sampledSynth, initMono + initNoDrop, nil);
SndNewChannel(&steveSndChannel, sampledSynth, initMono + initNoDrop, nil);
SndNewChannel(&computerSndChannel, sampledSynth, initMono + initNoDrop, nil);
SndNewChannel(&dojSndChannel, sampledSynth, initMono + initNoDrop, nil);
SndNewChannel(&otherSndChannel, sampledSynth, initMono + initNoDrop, nil);
SndNewChannel(&musicSndChannel, sampledSynth, initMono + initNoDrop, nil);
//weapon sounds
chainsawSnd = GetResource('snd ', 1000);
if (chainsawSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
jammedSnd = GetResource('snd ', 1001);
if (jammedSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//bill sounds
billScreamSnd = GetResource('snd ', 2000);
if (billScreamSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
billIndignantSnd = GetResource('snd ', 2001);
if (billIndignantSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//steve sounds
steveScreamSnd = GetResource('snd ', 3001);
if (steveScreamSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//computer sounds
macOSLoadedSnd = GetResource('snd ', 4000);
if (macOSLoadedSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
winXPLoadedSnd = GetResource('snd ', 4001);
if (winXPLoadedSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//dept of justice sounds
dojAppearsSnd = GetResource('snd ', 5001);
if (dojAppearsSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
dojCaughtSnd = GetResource('snd ', 5000);
if (dojCaughtSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//other sounds
bonkSnd = GetResource('snd ', 6000);
if (bonkSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
zoomSnd = GetResource('snd ', 6001);
if (zoomSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
poofSnd = GetResource('snd ', 6002);
if (poofSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
gongSnd = GetResource('snd ', 6003 );
if (gongSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
beepSnd = GetResource('snd ', 6004 );
if (beepSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//game sounds
gameOverSnd = GetResource('snd ', 7000);
if (gameOverSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
gamePausedSnd = GetResource('snd ', 7001);
if (gamePausedSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
yeahSnd = GetResource('snd ', 7002);
if (yeahSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
killSomeBillSnd = GetResource('snd ', 7003);
if (killSomeBillSnd == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
goodJobSound = GetResource('snd ', 7004);
if (goodJobSound == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
//music sounds
musicSounds[0] = GetResource('snd ', 10000);
musicSounds[1] = GetResource('snd ', 10001);
musicSounds[2] = GetResource('snd ', 10002);
musicSounds[3] = GetResource('snd ', 10003);
musicSounds[4] = GetResource('snd ', 10004);
musicSounds[5] = GetResource('snd ', 10005);
for (i = 0; i < 6; i++)
{
if (musicSounds[i] == NULL)
FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
}
}
#pragma mark -
//////////////////////////////////////////////////////
//Init DrawSprockets and attempt to switch to 640x480
//////////////////////////////////////////////////////
void DisplayInit (void)
{
// Startup DrawSprockets and fade to black
OSErr theError=DSpStartup();
GDHandle graphicsDevice = DMGetFirstScreenDevice(true); // activate the Display Manager
if (theError)
{
FatalErrorAlert("¥pError loading DrawSprockets.", "¥pDSpStartup();");
}
if (graphicsDevice == NULL)
{
DoAlert("¥pError getting reading graphics device..", "¥pFunction: DisplayInit(); Continuing...let's see if we can get away with this anyway.");
}
gDisplayAttributes.frequency=0;
gDisplayAttributes.reserved1=0;
gDisplayAttributes.reserved2=0;
gDisplayAttributes.colorNeeds=kDSpColorNeeds_Require;
gDisplayAttributes.colorTable=nil;
gDisplayAttributes.contextOptions=0;
gDisplayAttributes.gameMustConfirmSwitch=false;
gDisplayAttributes.reserved3[0]=0;
gDisplayAttributes.reserved3[1]=0;
gDisplayAttributes.reserved3[2]=0;
gDisplayAttributes.reserved3[3]=0;
gDisplayAttributes.displayBestDepth=16;//16 bit colour
gDisplayAttributes.displayDepthMask=kDSpDepthMask_16;
gDisplayAttributes.backBufferBestDepth=gDisplayAttributes.displayBestDepth;
gDisplayAttributes.backBufferDepthMask=gDisplayAttributes.displayDepthMask;
gDisplayAttributes.pageCount = 2;//two buffers, one onscreen, one offscreen
gDisplayAttributes.displayWidth=640;
gDisplayAttributes.displayHeight=480;
theError=DSpFindBestContext(&gDisplayAttributes, &gDisplayContext);
if (theError)
{
FatalErrorAlert("¥pError initing DrawSprockets", "¥pA suitable display context could not be found.");
}
//Set the blanking color to black
DSpSetBlankingColor(&myBlackColor);
theError=DSpContext_Reserve(gDisplayContext, &gDisplayAttributes);
if (theError)
{
DSpContext_FadeGammaIn(NULL, NULL);
FatalErrorAlert("¥pError reserving display context.", "¥pDrawSprockets must be fucked.");
}
DSpContext_FadeGammaOut(NULL, NULL);
//try to change to our resolution
theError = DSpContext_SetState(gDisplayContext, kDSpContextState_Active);
if (theError)
{
DSpContext_FadeGammaIn(NULL, NULL);
FatalErrorAlert("¥pError setting display resolution with DrawSprockets.", "¥pMaybe your monitor does not support a resolution of 640 by 480 pixels. ;");
}
theError = DSpContext_FadeGammaIn(NULL, NULL);
}
void DisplayReset(void)
{
DSpContext_FadeGammaOut(nil, nil);
DSpContext_SetState(gDisplayContext, kDSpContextState_Inactive);
DSpContext_FadeGammaIn(nil, nil);
DSpContext_Release(gDisplayContext);
DSpShutdown();
}